var win = $(window)
var win_w = win.width()
var w1024 = 1024
var poretion = {
  loc: {
    // 默认值
    anchorpoint: $('#anchorPoint').val() || 'anchorpoint'
  },
  locVal: function (obj) {
    obj = obj || {}
    var x
    for (x in this.loc) {
      if (!obj[this.loc[x]]) {
        obj[this.loc[x]] = undefined
      }
    }
    console.log(obj)
    return obj
  },
  GetQueryString: function (name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
    var str = window.location.search.substr(1).match(reg)
    if (str != null) return unescape(str[2])
    return null
  },
  formatSearch: function (se) {
    var obj = {}
    // 兼容location.search为空报错
    if (typeof se !== 'undefined' && se !== '') {
      se = se.substr(1)
      var arr = se.split('&'),
        newarr = []
      $.each(arr, function (i, v) {
        newarr = v.split('=')
        if (typeof obj[newarr[0]] === 'undefined') {
          obj[newarr[0]] = newarr[1]
        }
      })
    }
    return obj
  },
  rep: function (obj, o, n) {
    var reg, res
    reg = new RegExp('(\\?|&)' + o + '=[^&]*', 'ig')
    res = obj.replace(reg, '$1' + o + '=' + n)
    if (!reg.test(obj)) {
      res += (search ? '&' : '?') + o + '=' + n
    }
    return res
  },
  replaceUrl: function (url) {
    if (history.pushState && url && location.href.replace([location.protocol, location.host].join('//')) != url) {
      history.pushState(
        {
          title: document.title
        },
        document.title,
        [location.protocol, location.host].join('//') + url
      )
    }
  }
}

var loc = poretion.locVal(poretion.formatSearch(location.search))
if (poretion.loc.anchorpoint && loc[poretion.loc.anchorpoint]) {
  var top = 0
  if (win_w <= w1024) {
    top = 66
  }
  $('html,body').animate({
    scrollTop: $('[data-anchor-point=' + loc[poretion.loc.anchorpoint] + ']').offset().top - top
  })
}
